package cn.senjoeson.timedowner.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.senjoeson.timedowner.R;
import cn.senjoeson.timedowner.dao.DBConfig;
import cn.senjoeson.timedowner.dao.HeartDetailtDao;

/**
 * Created by senjoeson on 2017/12/27.
 */

public class WriteActivity extends AppCompatActivity {
    @BindView(R.id.backyourheartlist)
    TextView mBackyourheartlist;
    @BindView(R.id.save)
    TextView mSave;
    @BindView(R.id.above)
    LinearLayout mAbove;
    @BindView(R.id.heartContent)
    EditText mHeartContent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_write);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        final long titleid = getIntent().getLongExtra("titleid", 0);
        final HeartDetailtDao heartDetailBeanDao = new HeartDetailtDao(this, DBConfig.TABLE_NAME_2);

        mSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = mHeartContent.getText().toString().trim();
                if (!TextUtils.isEmpty(text)) {
                   heartDetailBeanDao.delete(titleid);
                  //  heartDetailBeanDao.insertWithoutSettingPk(heartDetailBean);
                    finish();
                } else {

                    Toast.makeText(WriteActivity.this, "请先填写内容,再保存哦!~", Toast.LENGTH_SHORT).show();
                }

            }
        });

        mBackyourheartlist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    @Override
    protected void onRestart() {
        super.onRestart();

    }
}
